home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Libris Britannia 4
/
science library(b).zip
/
science library(b)
/
CUGUK
/
PROG_TOO
/
C013.ZIP
/
TEE.C
< prev
next >
Wrap
Text File
|
1990-01-19
|
2KB
|
72 lines
/********************************************************************
* C Users Group (U.K) C Source Code Library File CUGLIB.013 *
* Inquiries to: M. Houston, 36 Whetstone Clo. Farquhar Rd. *
* Edgbaston, Birmingham B15 2QN ENGLAND *
********************************************************************
* File name: tee.c
* Program name:tee
* Source of file: Ron Wellstead
* Purpose: An MS-DOS copy of the UNIX utility of the same name.
* Changes: <who what when & why major changes have been made>
********************************************************************/
/*
*
* @(#) tee.c 1.2 87/07/27
*
* UNIX style tee utility for dos
*
* copyright (c) 1987 Ron Wellsted.
* This software is provided on the understanding that it is
* NOT to be used for commercial gain. It may be freely distributed
* in source or object form among amateur and hobby computer users ONLY!
*
* copies stdin to stdout and file
* usage: tee file
* normally used as part of a pipe eg dir | tee con | sort
* will display a directory both before and after sorting.
* written for Microsoft C.
*/
#include <stdio.h>
char what[]="@(#) tee VR 1.0.0 15 Jul 1987";
main(argc,argv)
int argc;
char *argv[];
{
char *cmd;
FILE *fp;
cmd=argv[1];
if (argc==1) /* no args; copy to stdout */
filecopy(NULL);
else if ((*cmd=='-')&&(tolower(*++cmd)=='a')) {
if ((fp=fopen(argv[2],"a"))==NULL) {
fprintf(stderr,"tee: can't open %s\n",argv[2]);
exit(1);
}
} else {
if ((fp=fopen(argv[1],"w"))==NULL) {
fprintf(stderr,"tee: can't create %s\n",argv[1]);
exit(1);
}
}
filecopy(fp);
fclose(fp);
exit(0);
}
filecopy(fp)
FILE *fp;
{
int c;
if (fp==NULL)
while ((c=getchar())!=EOF) putchar(c);
else while ((c=getchar())!=EOF) {
putchar(c);
putc(c,fp);
}
}